package ObserverMode.JavaUtilsEdition.subject;

import java.util.Observable;

/**
 * 将WeatherData改成继承自Observable
 *
 * @Author Li Cheng
 * @Date 2021/8/12 22:50
 * @Version 1.0
 */
public class WeatherData2 extends Observable {

    private float temperature;
    private float humidity;
    private float pressure;

    //不再需要为了记住注册者而建立数据结构
    public WeatherData2(){}

    //我们通知观察者,并传送数据过去
    public void measurementsChanged(){
        setChanged();
        notifyObservers();
    }

    //用来测试布告板,实际情况的是从装置中读取实际的值
    public void setMeasurements(float temperature,float humidity, float pressure){
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }

    //因为要使用'拉'操作，拉数据，所以有了下面这些方法
    public float getTemperature() {
        return temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public float getPressure() {
        return pressure;
    }
}
